import fs from "fs";
import "./heiti-normal.js";
export function addFontToPdf(pdf, fontName, fontPath) {
    const myFont = fs.readFileSync(fontPath); // load the *.ttf font file as binary string
    pdf.addFileToVFS(`${fontName}.ttf`, myFont.toString("binary"));
    pdf.addFont(`${fontName}.ttf`, fontName, "normal");
    pdf.setFont(fontName);
    return pdf;
}
/**
 *
 * @param pdf
 * @param pos 写字的位置
 * @param text
 * @param align
 * @param maxWidth 最宽文字
 * @param fontOption
 */
export function drawText(pdf, pos, text, align, maxWidth, fontOption) {
    const { name, size, color } = fontOption;
    const { x, y } = pos;
    pdf.setFont(name, "regular", "normal");
    pdf.setFontSize(size);
    pdf.setTextColor(color);
    const textOpt = {
        align,
        maxWidth,
    };
    pdf.text(text, x, y, textOpt);
}
